package com.dmz.spring.mvc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

@EnableAsync
@Configuration
public class AsyncConfig {

    @Bean
    public TaskExecutor executor() {
        final Executor executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() * 2);
        TaskExecutor taskExecutor = new TaskExecutor() {
            @Override
            public void execute(Runnable task) {
                executor.execute(task);
            }
        };
        return taskExecutor;
    }
}